Syntax10.Scn.Fnt Syntax10i.Scn.Fnt StampElems Alloc 31 Oct 94 Syntax10b.Scn.Fnt MODULE DialogGraphics; (* based on GraphicElems by CAS mod NW 19.3.91/ HM 27.9.93 *) (** Markus Knasm ller 22 Sep 94 - IMPORT DialogFrames, Dialogs, DialogTexts, Display, Files, GraphicFrames, Graphics, In, MenuViewers, Oberon, TextFrames, TextPrinter, Texts, Viewers; CONST MM = 1; ML = 0; MR = 2; menu = "System.Close System.Copy System.Grow Draw.Delete DialogGraphics.Update "; mm = TextFrames.mm; Scale = mm DIV 10; dUnit = TextFrames.Unit; pUnit = TextPrinter.Unit; GripW = 15 * Scale DIV dUnit; GripH = GripW; W* = 100; H* = 100; TYPE Item* = POINTER TO ItemDesc; ItemDesc* = RECORD(Dialogs.ObjectDesc) graph*: Graphics.Graph; empty: BOOLEAN; xg, yg: INTEGER; END; Frame = POINTER TO FrameDesc; FrameDesc = RECORD (GraphicFrames.FrameDesc) elem: Item END; VAR x0, x1, y0, y1: INTEGER; w: Texts.Writer; PROCEDURE box (obj: Graphics.Object; VAR done: BOOLEAN); BEGIN IF obj.x < x0 THEN x0 := obj.x END; IF x1 < obj.x + obj.w THEN x1 := obj.x + obj.w END; IF obj.y < y0 THEN y0 := obj.y END; IF y1 < obj.y + obj.h THEN y1 := obj.y + obj.h END END box; PROCEDURE Max (x, y: INTEGER): INTEGER; BEGIN IF x > y THEN RETURN x ELSE RETURN y END END Max; PROCEDURE CopyGraph (g: Graphics.Graph): Graphics.Graph; VAR g1: Graphics.Graph; BEGIN Graphics.SelectArea (g, MIN (INTEGER), MIN (INTEGER), MAX (INTEGER), MAX (INTEGER)); NEW (g1); Graphics.Copy (g, g1, 0, 0); Graphics.Deselect (g1); RETURN g1 END CopyGraph; PROCEDURE (g: Item) Draw* (x, y: INTEGER; f: Display.Frame); (** displays the object at (x, y) in frame f *) VAR x0, y0, w, h, mode: INTEGER; f1: GraphicFrames.Frame; BEGIN g.GetDim (x0, y0, w, h); IF g.selected THEN mode := Display.invert ELSE mode := Display.replace END; IF g.empty OR (x < f.X) OR (y < f.Y) OR (x + w > f.X + f.W) OR (y + h > f.Y + f.H) THEN Display.ReplPatternC (f, Display.white, Display.grey1, x, y, w, h, 0, 0, mode) ELSE NEW (f1); GraphicFrames.Open (f1, g.graph, g.xg, g.yg, f (DialogFrames.Frame).col, FALSE); f1.X := x; f1.Y := y; f1.W := w; f1.H := h; GraphicFrames.Restore (f1); END END Draw; PROCEDURE (g: Item) Print* (x, y: INTEGER); (** prints the object at printer coordinates (x, y) *) VAR x0, y0, w, h: INTEGER; BEGIN g.GetPDim (x0, y0, w, h); IF ~g.empty THEN Graphics.Print (g.graph, SHORT (g.xg * 4) + x, SHORT (g.yg * 4) + y + h) END END Print; PROCEDURE (g: Item) Copy* (VAR dup: Dialogs.Object); (** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *) VAR x: Item; BEGIN IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END; g.Copy^ (dup); x.graph := CopyGraph (g.graph); x.xg := g.xg; x.yg := g.yg; x.empty := g.empty END Copy; PROCEDURE (g: Item) Load* (VAR r: Files.Rider); (** reads the object from rider r *) BEGIN g.Load^ (r); Files.ReadBool (r, g.empty); Files.ReadInt (r, g.xg); Files.ReadInt (r, g.yg); NEW (g.graph); Graphics.Load (g.graph, r) END Load; PROCEDURE (g: Item) Store* (VAR r: Files.Rider); (** writes the object to rider r *) BEGIN g.Store^ (r); Files.WriteBool (r, g.empty); Files.WriteInt (r, g.xg); Files.WriteInt (r, g.yg); Graphics.Store (g.graph, r) END Store; PROCEDURE (g: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg); (** handles messages which were sent to frame f *) VAR t: Texts.Text; BEGIN g.Handle^ (f, m); WITH f: DialogFrames.Frame DO WITH m: Oberon.InputMsg DO IF (m.id = Oberon.track) & ((m.keys = {MM}) OR (m.keys = {MR}) OR (m.keys = {ML})) & (g.cmd[0] # 0X) THEN DialogTexts.GetParText (g.par, g.panel, t); g.CallCmd (f, Viewers.This (m.X, m.Y), t) END ELSE END ELSE END END Handle; PROCEDURE MarkMenu (f: Frame); VAR r: Texts.Reader; v: Viewers.Viewer; t: Texts.Text; ch: CHAR; BEGIN v := Viewers.This (f.X, f.Y); IF v IS MenuViewers.Viewer THEN t := v.dsc(TextFrames.Frame).text; IF t.len > 0 THEN Texts.OpenReader (r, t, t.len - 1); Texts.Read (r, ch) ELSE ch := 0X END; IF ch # "!" THEN Texts.Write (w, "!"); Texts.Append (t, w.buf) END END END MarkMenu; PROCEDURE HandleFrame (f0: Display.Frame; VAR msg: Display.FrameMsg); VAR f: Frame; f1: Frame; BEGIN f := f0(Frame); IF msg IS Oberon.InputMsg THEN GraphicFrames.Handle (f, msg); WITH msg: Oberon.InputMsg DO IF (msg.id = Oberon.consume) OR (msg.id = Oberon.track) & (msg.keys # {}) THEN MarkMenu (f) END END ELSIF msg IS Oberon.CopyMsg THEN NEW (f1); GraphicFrames.Open (f1, f.graph, f.Xg, f.Yg, f.col, f.ticked); f1.handle := f.handle; f1.elem := f.elem; msg(Oberon.CopyMsg).F := f1 ELSE GraphicFrames.Handle (f, msg) END END HandleFrame; PROCEDURE (g: Item) Edit* (); (** opens a graphic frame for editing the properties of the object *) VAR v: Viewers.Viewer; f: Frame; x, y: INTEGER; BEGIN NEW (f); GraphicFrames.Open (f, CopyGraph (g.graph), 0, 0, Display.black, TRUE); f.elem := g; f.handle := HandleFrame; Oberon.AllocateSystemViewer (Oberon.Mouse.X, x, y); v := MenuViewers.New (TextFrames.NewMenu ("DialogGraphics.Graph", menu), f, TextFrames.menuH, x, y) END Edit; PROCEDURE (g: Item) Open; BEGIN x0 := MAX (INTEGER); x1 := MIN (INTEGER); y0 := MAX (INTEGER); y1 := MIN (INTEGER); Graphics.Enumerate (g.graph, box); IF x0 = MAX (INTEGER) THEN x0 := 0; y0 := 0; g.empty := TRUE; g.xg := 0; g.yg := 0 ELSE g.xg := - x0; g.yg := - y1; DEC (x1, x0); DEC (y1, y0); g.empty := FALSE END END Open; PROCEDURE Insert*; (** Insert (name | ^ ) inserts a graphic - item in the panel containing the caret position *) VAR w, h, x, y, xh, yh: INTEGER; g: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR; BEGIN NEW (g); DialogFrames.GetCaretPosition (p, x, y); IF (p # NIL) THEN g.Init; In.Open; In.Name (name); IF ~In.Done THEN COPY ("", name); In.Open END; g.SetName (name); NEW (g.graph); Graphics.Open (g.graph, name); g.Open; In.Int (xh); In.Int (yh); In.Int (w); In.Int (h); IF In.Done THEN w := Max (x1, w); h := Max (y1, h); x := xh; y := yh; ELSIF g.empty THEN w := W; h := H ELSE w := x1; h := y1 END; g.SetDim (x, y, w, h, FALSE); p.Insert (g, FALSE) ELSE Dialogs.res := Dialogs.noPanelSelected END; IF Dialogs.res # 0 THEN Dialogs.Error ("DialogGraphics") END; END Insert; PROCEDURE Update*; VAR v: Viewers.Viewer; f: Frame; r: Texts.Reader; t: Texts.Text; ch: CHAR; x, y, w, h: INTEGER; BEGIN v := Oberon.Par.vwr; f := v.dsc.next(Frame); t := v.dsc(TextFrames.Frame).text; GraphicFrames.Deselect (f); f.elem.graph := CopyGraph (f.graph); f.elem.Open; f.elem.GetDim (x, y, w, h); w := Max (x1, w); h := Max (y1, h); f.elem.SetDim (x, y, w, h, FALSE); f.elem.Restore; f.elem.panel.MarkMenu; Texts.OpenReader (r, t, t.len - 1); Texts.Read (r, ch); IF ch = "!" THEN Texts.Delete (t, t.len - 1, t.len) END END Update; BEGIN Texts.OpenWriter (w) END DialogGraphics.